const state = () => ({
  position: {},
  hotCity: []
})

const mutations = {
  setPosition(state, val) {
    state.position = val
  },
  setHotCity(state, val) {
    state.hotCity = val
  }
}

const actions = {
  setPosition: ({dispatch, commit}, position) => {
    commit('setPosition', position)
    dispatch('home/setHotPlace', position.city, {root: true})
  },
  setHotCity: ({commit}, hotCity) => {
    if (hotCity.name === '市辖区') {
      hotCity.name = hotCity.province
      hotCity.province = '市辖区'
    }
    commit('setHotCity', hotCity)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
